﻿@using ServiceStack.Html
@model AcexeService.Models.HomeViewModel
@{
    ViewBag.Title = "Acexe WMS - WebService 首页";
    var session = Model.Session;
    var userName = session.UserName ?? session.Email ?? "ACEXE0001";        
}

@section scripts 
{
    <script src="/api/js/ss-utils.js"></script>
    <script src="/Scripts/autogrid.js"></script>
    <script type="text/javascript">
        var hashVars = $.ss.queryString(location.hash.replace('#', '?'));
        if (hashVars['f']) {
            $("#autherror").html($.ss.humanize(hashVars['f']));
        }

        $.getJSON("/api/auth", function (r) {
            var html = "<h4 class='success'>Authenticated!</h4>"
                + "<table>"
                + $.map(r, function (k, v) {
                    return "<tr><th>" + v + "<th>"
                        + "<td>" + (typeof k == 'string' ? k : JSON.stringify(k)) + "</td></tr>";
                }).join('')
                + "</table>";
            $("#status").html(html);
        }).error(function () {
            $("#status").html("<h4 class='error'>Not Authenticated</h4>");
        });

        $(document).bindHandlers({
            switchUser: function (u) {
                $("#userName").val(u);
                $("#password").val('test');
            }
        });

        $("#form-register").bindForm({
            success: function (r) { location.href = '/'; }
        });

        var html = autogrid( @(Model.UserAuths.AsRawJson()));
        $("#userauths").html(html);
        html = autogrid( @(Model.UserAuthDetails.AsRawJson()));
    $("#userauthdetails").html(html);
    </script>
}

<div class="jumbotron">
    <h3>AcexeService</h3>
    <p class="lead">
        艾希 wms 产品组 webservice 小组
    </p>
</div>

<div class="row">
    <div class="col-lg-6">

        @if (session.IsAuthenticated)
        {
            <h2 class="success">Authenticated!</h2>  
        }
        else
        {
            <h2 class="error">Not Authenticated</h2>
        }
        <div id="autherror" class="error"></div>

        <form action="/Home/Login">
            @Html.ValidationSummary()
            <input type="hidden" name="redirect" value="@Request.QueryString["redirect"]"/>

            <div class="form-group">
                <input class="form-control input-lg" id="userName" name="userName" type="text" placeholder="UserName" value="@userName">
            </div>
            <div class="form-group form-inline">
                <input class="form-control input-lg" id="password" name="password" type="password" placeholder="Password" value="1234">
                <button type="submit" class="btn btn-lg btn-default">Login</button>
            </div>
            <div style="margin: 10px">
                <b>Quick Login:</b>
                <span data-click="switchUser:ACEXE0001">ACEXE0001</span>
            </div>
        </form>

        <form action="/Home/Logout">
            <button type="submit" class="btn btn-default">Logout</button>
        </form>

    </div>
    <div class="col-lg-6">

        <h2 style="margin: 30px 0 0 0;">登录信息 (Ajax)</h2>
        <div id="status"></div>

        <table class="table table-striped" style="margin: 20px 0 0 0">
            <tr>
                <th colspan="2">ServiceStack Auth &amp; Session Links:</th>
            </tr>
            <tr>
                <th>View Session Info</th>
                <td><a href="/api/session">/api/session</a></td>
            </tr>
            <tr>
                <th>Edit Session Info</th>
                <td><a href="/api/session/edit/ANYTEXT">/api/session/edit/ANYTEXT</a></td>
            </tr>
            <tr>
                <th>AuthOnly Page</th>
                <td><a href="/AuthOnly">/AuthOnly</a></td>
            </tr>
            <tr>
                <th>Requires Role Page</th>
                <td><a href="/RequiresRole">/RequiresRole</a></td>
            </tr>
            <tr>
                <th>Reset All User Info</th>
                <td><a href="/api/reset">/api/reset</a></td>
            </tr>
        </table>
    </div>
</div>
<hr />
<div class="row">
    <div class="col-lg-6">
        <h3>使用第三方帐号登录</h3>
        <div style="float: left; width: 250px; padding: 0 0 0 0;">
            <a class="btn btn-block btn-social btn-twitter" href="/api/auth/twitter">
                <b class="fa fa-twitter">T</b>Sign in with Twitter
            </a>
            <a class="btn btn-block btn-social btn-facebook" href="/api/auth/facebook">
                <b class="fa fa-facebook">fb</b>Sign in with Facebook
            </a>
            <a class="btn btn-block btn-social btn-github" href="/api/auth/github">
                <b class="fa fa-github"></b>Sign in with GitHub
            </a>
            <a class="btn btn-block btn-social btn-google-plus" href="/api/auth/GoogleOAuth">
                <b class="fa fa-google-plus">G</b>Sign in with Google
            </a>
            <a class="btn btn-block btn-social btn-yahoo" href="/api/auth/YahooOpenId">
                <b class="fa fa-yahoo">Y!</b>Sign in with Yahoo
            </a>
            <a class="btn btn-block btn-social btn-linkedin" href="/api/auth/LinkedIn">
                <b class="fa fa-linkedin">in</b>Sign in with LinkedIn
            </a>
            <a class="btn btn-block btn-social btn-vk" href="/api/auth/vkcom">
                <b class="fa fa-vk"></b>Sign in with VK
            </a>
            <a class="btn btn-block btn-social btn-yandex" href="/api/auth/Yandex">
                <b class="fa fa-yandex">Y</b>Sign in with <b>Y</b>andex
            </a>

            <br />

            <a class="btn btn-block btn-social btn-windows" href="/api/auth/windowsauth">第三方登录（暂不支持）
            </a>
        </div>
    </div>
    <div class="col-lg-6">
        <h3>注册帐户</h3>
        <form id="form-register" action="/api/register" method="POST">
            <div class="form-group">
                <input class="form-control input-lg" type="text" name="FirstName" value="New" placeholder="First Name">
                <span class="help-block"></span>
            </div>
            <div class="form-group">
                <input class="form-control input-lg" type="text" name="LastName" value="User" placeholder="Last Name">
                <span class="help-block"></span>
            </div>
            <div class="form-group">
                <input class="form-control input-lg" type="text" name="Email" value="new.user@gmail.com" placeholder="Email">
                <span class="help-block"></span>
            </div>
            <div class="form-group">
                <input class="form-control input-lg" type="text" name="Password" value="test" placeholder="Password">
                <span class="help-block"></span>
            </div>
            <div class="form-group">
                <input type="checkbox" id="chkAutoLogin" name="AutoLogin" value="true" checked="checked">
                <label for="chkAutoLogin">Auto Login</label>
            </div>
            <div class="form-group">
                <button class="btn btn-lg btn-default" type="submit">Register</button>
            </div>
            <div class="clearfix"></div>
        </form>
    </div>
</div>

@section footer {
    <div style="padding: 10px; font-size: 14px;">
        @if (!Model.UserAuths.IsEmpty())
        {
            <h3>在线用户</h3>
            <div class="autogrid" id="userauths"></div>
        }

        @if (!Model.UserAuthDetails.IsEmpty())
        {
            <h3>登录用户明细</h3>
            <div class="autogrid" id="userauthdetails"></div>
        }
    </div>


}
